home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- '''addressclassifier.py - Core SpamExpert classes.
-
- Classes:
-
- AddressClassifier - base class for the black and white lists
- DBDictAddressClassifier - persistent black/white list
- ZODBAddressClassifier - black/white list that uses ZODB for
- persistence
- '''
- import sys
- import types
- import shelve
- import ZODB
-
- try:
- from persistent import Persistent
- except ImportError:
- from ZODB import Persistent
-
- from BTrees.OOBTree import OOBTree
- from spambayes import dbmstorage
- from spambayes.classifier import Classifier, PICKLE_VERSION
- from spambayes.storage import STATE_KEY, DBDictClassifier, ZODBClassifier
- from spamexperts.Options import options
-
- class AddressClassifier(Classifier):
-
- def spamprob(self, address, evidence = False):
- '''Return best-guess probability that a message from address is
- spam.
-
- The return value is a float in [0.0, 1.0].
-
- If optional arg evidence is True, the return value is a pair
- probability, evidence
- where evidence is a list of (word, probability) pairs.
- '''
-
- try:
- record = self._wordinfoget(address)
- except UnicodeDecodeError:
- record = None
-
- if record is None:
- prob = options[('Classifier', 'unknown_word_prob')]
- elif record.spamcount > record.hamcount:
- prob = 1.0
- else:
- prob = 0.0
- if evidence:
- return (prob, [])
- else:
- return prob
-
-
- def learn(self, address, is_spam):
- """Teach the classifier by example.
-
- If is_spam is True, you're telling the classifier that messages
- from this address are definitely spam, else that they are
- definitely not spam.
- """
- if not isinstance(address, types.UnicodeType):
- address = unicode(address, 'latin-1')
-
- self._add_msg((address,), is_spam)
-
-
- def unlearn(self, address, is_spam):
- '''In case of pilot error, call unlearn ASAP after screwing up.
-
- Pass the same arguments you passed to learn().
- '''
- if not isinstance(address, types.UnicodeType):
- address = unicode(address, 'latin-1')
-
- self._remove_msg((address,), is_spam)
-
-
- def forget(self, address):
- '''Forget about this address completely.'''
- if address in self._wordinfokeys():
- self._wordinfodel(address)
-
-
-
- def keys(self, is_spam = None):
- keys = self._wordinfokeys()
- return keys
-
-
-
- class DBDictAddressClassifier(AddressClassifier, DBDictClassifier):
- '''AddressClassifier object persisted in a caching database.'''
- pass
-
-
- class _PersistentAddressClassifier(AddressClassifier, Persistent):
-
- def __init__(self):
- AddressClassifier.__init__(self)
- self.wordinfo = OOBTree()
-
-
-
- class ZODBAddressClassifier(ZODBClassifier):
- ClassifierClass = _PersistentAddressClassifier
-
-